<template>
    <div style="margin: 10px 0;">
        <el-select v-model="searchStatus" placeholder="请选择审核情况">
            <el-option label="所有" value="" @click="checkPaper()"></el-option>
            <el-option label="审核中" value="审核中" @click="checkPaper()"></el-option>
            <el-option label="审核通过" value="审核通过" @click="checkPaper()"></el-option>
            <el-option label="审核失效" value="审核失效" @click="checkPaper()"></el-option>
            <el-option label="未提交" value="未提交" @click="checkPaper()"></el-option>
        </el-select>
        <el-input v-model="searchPaperName" placeholder="按论文名称搜索" style=" width: 20%;" clearable></el-input>
        <el-input v-model="searchPublicationName" placeholder="按发表刊物名称搜索" style=" width: 20%;" clearable></el-input>
        <el-date-picker v-model="searchYear" type="year" @change="checkPaper()" placeholder="选择发表年份"  />
        <el-button style="margin-left:5px ;" @click="checkPaper()">
            <el-icon>
                <search />
            </el-icon><span style="margin-left: 5px;">查询</span>
        </el-button>
        <el-button type="primary" style="margin-left:30px ;" @click="checkAdd()">
            <el-icon>
                <document-add />
            </el-icon><span style="margin-left: 5px;">添加</span>
        </el-button>
        <el-button type="primary" @click="dialogExcel = true">导入学术论文信息</el-button>
        <el-table :data="tableData" stripe style="width: 100%;margin-top: 10px;">
            <el-table-column prop="id" label="ID" sortable />
            <el-table-column prop="paperName" label="论文名称" />
            <el-table-column prop="paperType" label="类型" />
            <el-table-column label="状态">
                <template #default="scope">
                    <el-tag vclass="ml-2" v-if="scope.row.status == '审核通过'">{{scope.row.status}}</el-tag>
                    <el-tag vclass="ml-2" type="warning" v-else-if="scope.row.status == '审核中'">{{scope.row.status}}
                    </el-tag>
                    <el-tag vclass="ml-2" type="info" v-else-if="scope.row.status == '未提交'">{{scope.row.status}}
                    </el-tag>
                    <el-tag vclass="ml-2" type="danger" v-else>{{scope.row.status}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="inputPeople" label="录入人" />
            <el-table-column label="操作">
                <template #default="scope">
                    <el-button type="text" @click="checkUp(scope.row)">信息详情</el-button>
                    <el-button type="text" @click="dealFile(scope.row)">附件详情</el-button>
                    <el-popconfirm title="确定提交审核吗？" v-if="scope.row.status == '未提交'||scope.row.status == '审核失效'"
                        @confirm="dealStatus(scope.row,'审核中')">
                        <template #reference>
                            <el-button type="text">提交审核</el-button>
                        </template>
                    </el-popconfirm>
                    <el-popconfirm title="确定退回修改吗？" v-if="scope.row.status == '审核中'"
                        @confirm="dealStatus(scope.row,'未提交')">
                        <template #reference>
                            <el-button type="text">退回修改</el-button>
                        </template>
                    </el-popconfirm>
                    <el-popconfirm title="这些内容确定删除吗？" v-if="scope.row.status == '未提交' ||scope.row.status == '审核失效'"
                        @confirm="deleteFile(scope.row)">
                        <template #reference>
                            <el-button type="text">删除</el-button>
                        </template>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <div class="demo-pagination-block">
            <div style="float: right;">
                <el-pagination :currentPage="current" :page-sizes="[10,20,30]" :page-size=page
                    layout="sizes, prev, pager, next,total,jumper" :total=firstTotal @size-change="handleSize"
                    @current-change="handleCurrent">
                </el-pagination>
            </div>
        </div>

        <el-dialog v-model="dialogAddPaper" title="录入学术论文信息" width="60%" center>
            <el-form ref="paper" :model="paper" :rules="rules" label-width="200px" class="demo-ruleForm"
                :size="formSize">


                <el-form-item label="论文名称" prop="paperName">
                    <el-input v-model="paper.paperName" placeholder="请输入论文名称"></el-input>
                </el-form-item>


                <el-form-item label="发表刊物名称" prop="publicationName">
                    <el-input v-model="paper.publicationName" placeholder="请输入发表刊物名称"></el-input>
                </el-form-item>

                <el-form-item label="发表时间" required>
                    <el-col :span="11">
                        <el-form-item prop="publicationTime">
                            <el-date-picker v-model="paper.publicationTime" type="date" placeholder="选择日期"
                                style="width: 100%"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-form-item>

                <el-form-item label="期刊ISSN号">
                    <el-input v-model="paper.isnn" placeholder="请输入期刊ISSN号"></el-input>
                </el-form-item>

                <el-form-item label="期刊CN号">
                    <el-input v-model="paper.cn" placeholder="请输入期刊CN号"></el-input>
                </el-form-item>

                <el-form-item label="期号/卷号">
                    <el-input style="width: 20%;" v-model="paper.issueNumber" placeholder="请输入期号"></el-input>
                    <el-input style="width: 20%; margin-left: 10px;" v-model="paper.volumeNumber" placeholder="请输入卷号">
                    </el-input>
                </el-form-item>

                <el-form-item label="页码范围">
                    <el-input v-model="paper.pageRange" placeholder="请输入页码范围"></el-input>
                </el-form-item>


                <el-form-item label="类型" prop="paperType">
                    <el-radio-group v-model="paper.paperType">
                        <el-radio label="会议论文"></el-radio>
                        <el-radio label="期刊论文"></el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="刊类别">
                    <el-radio-group v-model="paper.journalCategory">
                        <el-radio label="正刊"></el-radio>
                        <el-radio label="副刊"></el-radio>
                        <el-radio label="增刊"></el-radio>
                        <el-radio label="其他"></el-radio>
                    </el-radio-group>
                </el-form-item>
                
                <el-form-item label="通讯作者" >
                    <el-input v-model="paper.communicationAuthor" placeholder="请输入通讯作者"></el-input>
                </el-form-item>
                <el-form-item label="通讯作者单位" >
                    <el-input v-model="paper.communicationUnit" placeholder="请输入通讯作者单位"></el-input>
                </el-form-item>

                <el-form-item label="是否教改论文">
                    <el-switch size="large" v-model="paper.teachingReformPapers" inline-prompt active-text="是"
                        inactive-text="否">
                    </el-switch>
                </el-form-item>

                <el-form-item label="是否高引用">
                    <el-switch size="large" v-model="paper.highReference" inline-prompt active-text="是"
                        inactive-text="否">
                    </el-switch>
                </el-form-item>

                <el-form-item label="收录">
                    <el-checkbox-group v-model="collection">
                        <el-checkbox label="被中国人大《复印资料》转载的论文" name="collection"></el-checkbox>
                        <el-checkbox label="CCF A类" name="collection"></el-checkbox>
                        <el-checkbox label="CCF B类" name="collection"></el-checkbox>
                        <el-checkbox label="CCF C类" name="collection"></el-checkbox>
                        <el-checkbox label="CPCI-S" name="collection"></el-checkbox>
                        <el-checkbox label="CSCD" name="collection"></el-checkbox>
                        <el-checkbox label="EI" name="collection"></el-checkbox>
                        <el-checkbox label="ESI高被引论文" name="collection"></el-checkbox>
                        <el-checkbox label="ESI扩展版" name="collection"></el-checkbox>
                        <el-checkbox label="ESI工程学科期刊" name="collection"></el-checkbox>
                        <el-checkbox label="ESI论文他引" name="collection"></el-checkbox>
                        <el-checkbox label="ESI热点论文" name="collection"></el-checkbox>
                        <el-checkbox label="ISSHP" name="collection"></el-checkbox>
                        <el-checkbox label="ISTP" name="collection"></el-checkbox>
                        <el-checkbox label="普通期刊" name="collection"></el-checkbox>
                        <el-checkbox label="SCI一区" name="collection"></el-checkbox>
                        <el-checkbox label="SCI二区" name="collection"></el-checkbox>
                        <el-checkbox label="SCI三区" name="collection"></el-checkbox>
                        <el-checkbox label="SCI四区" name="collection"></el-checkbox>
                        <el-checkbox label="《SCIENCE》《NATURE》正刊论文" name="collection"></el-checkbox>
                        <el-checkbox label="《SCIENCE》《NATURE》子刊论文" name="collection"></el-checkbox>
                        <el-checkbox label="SSCI一区" name="collection"></el-checkbox>
                        <el-checkbox label="SSCI二区" name="collection"></el-checkbox>
                        <el-checkbox label="SSCI三区" name="collection"></el-checkbox>
                        <el-checkbox label="SSCI四区" name="collection"></el-checkbox>
                        <el-checkbox label="学校认定的中文权威期刊（理工)" name="collection"></el-checkbox>
                        <el-checkbox label="其他" name="collection"></el-checkbox>
                    </el-checkbox-group>
                </el-form-item>


                <el-form-item label="录入人">
                    {{paper.inputPeople}}
                </el-form-item>

                <el-form-item label="论文扫描件">
                    <el-upload ref="upload" class="upload-demo" drag action="#" :http-request="uploadFile">
                        <el-icon class="el-icon--upload">
                            <upload-filled />
                        </el-icon>
                        <div class="el-upload__text">
                            拖放文件 <em>上传文件</em>
                        </div>
                    </el-upload>
                </el-form-item>


                <el-form-item label="参与人员">
                    <div>
                        <el-button size="small" type="primary" @click="addAccount()">选择本单位人员</el-button>
                        <el-button size="small" @click="addStudent()">增加学生或外单位人员</el-button>
                        <el-button size="small" type="primary" @click="addOneSelf()">增加本人</el-button>
                    </div>
                    <div style="margin-top: 10px;">
                        <el-table :data="paper.participants" max-height="250" style="width: 100%">
                            <el-table-column label="排序">
                                <template #default="scope">
                                    <el-input-number :min="1" controls-position="right"
                                        v-model.number="scope.row.sortNumber" style="width: 100px"></el-input-number>
                                </template>
                            </el-table-column>
                            <el-table-column label="姓名">
                                <template #default="scope">
                                    <span style="color:#67b6ff" v-if="scope.row.usersId!=null"
                                        type="text">{{scope.row.participantName}}</span>
                                    <el-input v-model="scope.row.participantName" placeholder="请输入姓名" v-else></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="参与方式">
                                <template #default="scope">
                                    <el-input v-model="scope.row.participationMode" placeholder="请输入参与方式"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="工作单位">
                                <template #default="scope">
                                    <el-input v-model="scope.row.workPlace" v-if="scope.row.usersId!=null" disabled>
                                    </el-input>
                                    <el-input v-model="scope.row.workPlace" v-else></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="类别">
                                <template #default="scope">
                                    <span style="color:#67b6ff" v-if="scope.row.usersId!=null"
                                        type="text">{{scope.row.category}}</span>
                                    <el-select v-model="scope.row.category" placeholder="类别" v-else>
                                        <el-option label="老师" value="老师"></el-option>
                                        <el-option label="学生" value="学生"></el-option>
                                        <el-option label="外单位" value="外单位"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作">
                                <template #default="scope">
                                    <el-button style="color: red;" type="text" @click="deleteOne(scope.$index)">删除
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button size="large" type="primary" @click="submitAddPaper('paper')">保存学术论文
                    </el-button>
                </el-form-item>

            </el-form>
        </el-dialog>

        <el-dialog v-model="dialogAddAccount" title="录入学术论文信息" width="30%" center>
            <el-select v-model="searchRoles" style=" width: 20%;" placeholder="请选择角色类别">
                <el-option label="所有" value="" @click="checkRoles()"></el-option>
                <el-option label="管理员" value="管理员" @click="checkRoles()"></el-option>
                <el-option label="老师" value="老师" @click="checkRoles()"></el-option>
                <el-option label="研究生" value="研究生" @click="checkRoles()"></el-option>
            </el-select>
            <el-input v-model="searchName" placeholder="按名搜索" style=" width: 20%;" clearable></el-input>
            <el-button style="margin-left:5px ;" @click="checkRoles()">
                <el-icon>
                    <search />
                </el-icon><span style="margin-left: 5px;">查询</span>
            </el-button>
            <el-button style="margin-left:5px ;" type="primary" @click="addListparticipants()">
                <span>添加</span>
            </el-button>
            <div style="margin-top: 10px;">
                <el-table ref="multipleTableRef" :data="AccountTableData" @selection-change="handleSelectionChange"
                    @row-click="textRowClick" stripe style="width: 100%">
                    <el-table-column type="selection" width="55" />
                    <el-table-column prop="participantName" label="姓名" />
                    <el-table-column prop="workPlace" label="工作单位" />
                    <el-table-column prop="category" label="类别" />
                </el-table>
            </div>
            <div class="demo-pagination-block">
                <div style="float: right;">
                    <el-pagination :currentPage="currentPage" :page-size=pageSize
                        layout="prev, pager, next,total,jumper" :total=total @current-change="handleCurrentChange">
                    </el-pagination>
                </div>
            </div>

            <!-- 多留空间好看 -->
            <div style="margin-top: 10px;"></div>
        </el-dialog>

        <el-dialog v-model="dialogUpPaper" title="学术论文信息详情" width="60%" center>
            <el-form ref="paper" :model="paper" :rules="rules" label-width="200px" class="demo-ruleForm"
                :size="formSize">


                <el-form-item label="论文名称" prop="paperName">
                    <el-input v-model="paper.paperName" placeholder="请输入论文名称"></el-input>
                </el-form-item>


                <el-form-item label="发表刊物名称" prop="publicationName">
                    <el-input v-model="paper.publicationName" placeholder="请输入发表刊物名称"></el-input>
                </el-form-item>

                <el-form-item label="发表时间" required>
                    <el-col :span="11">
                        <el-form-item prop="publicationTime">
                            <el-date-picker v-model="paper.publicationTime" type="date" placeholder="选择日期"
                                style="width: 100%"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-form-item>

                <el-form-item label="期刊ISSN号">
                    <el-input v-model="paper.isnn" placeholder="请输入期刊ISSN号"></el-input>
                </el-form-item>

                <el-form-item label="期刊CN号">
                    <el-input v-model="paper.cn" placeholder="请输入期刊CN号"></el-input>
                </el-form-item>

                <el-form-item label="期号/卷号">
                    <el-input style="width: 20%;" v-model="paper.issueNumber" placeholder="请输入期号"></el-input>
                    <el-input style="width: 20%; margin-left: 10px;" v-model="paper.volumeNumber" placeholder="请输入卷号">
                    </el-input>
                </el-form-item>

                <el-form-item label="页码范围">
                    <el-input v-model="paper.pageRange" placeholder="请输入页码范围"></el-input>
                </el-form-item>


                <el-form-item label="类型" prop="paperType">
                    <el-radio-group v-model="paper.paperType">
                        <el-radio label="会议论文"></el-radio>
                        <el-radio label="期刊论文"></el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="刊类别">
                    <el-radio-group v-model="paper.journalCategory">
                        <el-radio label="正刊"></el-radio>
                        <el-radio label="副刊"></el-radio>
                        <el-radio label="增刊"></el-radio>
                        <el-radio label="其他"></el-radio>
                    </el-radio-group>
                </el-form-item>
                
                <el-form-item label="通讯作者" >
                    <el-input v-model="paper.communicationAuthor" placeholder="请输入通讯作者"></el-input>
                </el-form-item>
                
                <el-form-item label="通讯作者单位" >
                    <el-input v-model="paper.communicationUnit" placeholder="请输入通讯作者单位"></el-input>
                </el-form-item>

                <el-form-item label="是否教改论文">
                    <el-switch size="large" v-model="paper.teachingReformPapers" inline-prompt active-text="是"
                        inactive-text="否">
                    </el-switch>
                </el-form-item>

                <el-form-item label="是否高引用">
                    <el-switch size="large" v-model="paper.highReference" inline-prompt active-text="是"
                        inactive-text="否">
                    </el-switch>
                </el-form-item>

                <el-form-item label="收录">
                    <el-checkbox-group v-model="collection">
                        <el-checkbox label="被中国人大《复印资料》转载的论文" name="collection"></el-checkbox>
                        <el-checkbox label="CCF A类" name="collection"></el-checkbox>
                        <el-checkbox label="CCF B类" name="collection"></el-checkbox>
                        <el-checkbox label="CCF C类" name="collection"></el-checkbox>
                        <el-checkbox label="CPCI-S" name="collection"></el-checkbox>
                        <el-checkbox label="CSCD" name="collection"></el-checkbox>
                        <el-checkbox label="EI" name="collection"></el-checkbox>
                        <el-checkbox label="ESI高被引论文" name="collection"></el-checkbox>
                        <el-checkbox label="ESI扩展版" name="collection"></el-checkbox>
                        <el-checkbox label="ESI工程学科期刊" name="collection"></el-checkbox>
                        <el-checkbox label="ESI论文他引" name="collection"></el-checkbox>
                        <el-checkbox label="ESI热点论文" name="collection"></el-checkbox>
                        <el-checkbox label="ISSHP" name="collection"></el-checkbox>
                        <el-checkbox label="ISTP" name="collection"></el-checkbox>
                        <el-checkbox label="普通期刊" name="collection"></el-checkbox>
                        <el-checkbox label="SCI一区" name="collection"></el-checkbox>
                        <el-checkbox label="SCI二区" name="collection"></el-checkbox>
                        <el-checkbox label="SCI三区" name="collection"></el-checkbox>
                        <el-checkbox label="SCI四区" name="collection"></el-checkbox>
                        <el-checkbox label="《SCIENCE》《NATURE》正刊论文" name="collection"></el-checkbox>
                        <el-checkbox label="《SCIENCE》《NATURE》子刊论文" name="collection"></el-checkbox>
                        <el-checkbox label="SSCI一区" name="collection"></el-checkbox>
                        <el-checkbox label="SSCI二区" name="collection"></el-checkbox>
                        <el-checkbox label="SSCI三区" name="collection"></el-checkbox>
                        <el-checkbox label="SSCI四区" name="collection"></el-checkbox>
                        <el-checkbox label="学校认定的中文权威期刊（理工)" name="collection"></el-checkbox>
                        <el-checkbox label="其他" name="collection"></el-checkbox>
                    </el-checkbox-group>
                </el-form-item>


                <el-form-item label="录入人">
                    {{paper.inputPeople}}
                </el-form-item>


                <el-form-item label="参与人员">
                    <div v-if="cheackOrDeal">
                        <el-button size="small" type="primary" @click="addAccount()">选择本单位人员</el-button>
                        <el-button size="small" @click="addStudent()">增加学生或外单位人员</el-button>
                        <span>（对参与人员的修改可能会很慢）</span>
                    </div>
                    <div style="margin-top: 10px;">
                        <el-table :data="paper.participants" max-height="250" style="width: 100%">
                            <el-table-column label="排序">
                                <template #default="scope">
                                    <el-input-number :min="1" controls-position="right"
                                        v-model.number="scope.row.sortNumber" style="width: 100px"></el-input-number>
                                </template>
                            </el-table-column>
                            <el-table-column label="姓名">
                                <template #default="scope">
                                    <span style="color:#67b6ff" v-if="scope.row.usersId!=null"
                                        type="text">{{scope.row.participantName}}</span>
                                    <el-input v-model="scope.row.participantName" placeholder="请输入姓名" v-else></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="参与方式">
                                <template #default="scope">
                                    <el-input v-model="scope.row.participationMode" placeholder="请输入参与方式"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="工作单位">
                                <template #default="scope">
                                    <el-input v-model="scope.row.workPlace" v-if="scope.row.usersId!=null" disabled>
                                    </el-input>
                                    <el-input v-model="scope.row.workPlace" v-else></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="类别">
                                <template #default="scope">
                                    <span style="color:#67b6ff" v-if="scope.row.usersId!=null"
                                        type="text">{{scope.row.category}}</span>
                                    <el-select v-model="scope.row.category" placeholder="类别" v-else>
                                        <el-option label="老师" value="老师"></el-option>
                                        <el-option label="学生" value="学生"></el-option>
                                        <el-option label="外单位" value="外单位"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作">
                                <template #default="scope">
                                    <el-button style="color: red;" type="text" @click="deleteOne(scope.$index)">删除
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </el-form-item>
                <el-form-item v-if="cheackOrDeal">
                    <el-button size="large" type="primary" @click="submitUpPaper('paper')">保存学术论文
                    </el-button>
                </el-form-item>

            </el-form>
        </el-dialog>


        <el-dialog v-model="dialogDealFile" title="附件详情" width="30%" center>
            <div style="text-align: center;">
                <el-button type="success" @click="getFile">下载附件</el-button>
                <el-divider style="border-width: 3px;"></el-divider>

                <el-upload ref="updataFile" class="upload-demo" drag action="#" :http-request="UpFile"
                    v-if="cheackOrDeal">
                    <el-icon class="el-icon--upload">
                        <upload-filled />
                    </el-icon>
                    <div class="el-upload__text">
                        拖放文件 <em>修改文件</em>
                    </div>
                </el-upload>
            </div>
        </el-dialog>

        <el-dialog v-model="dialogExcel" title="导入学术论文信息" width="30%" center>
            <div style="text-align: center;">
                <el-button type="success" @click="getExcelType">下载Excel模板</el-button>
                <el-divider style="border-width: 3px;"></el-divider>

                <el-upload class="upload-demo" drag ref="uploadExcel" action="#"
                    accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                    :http-request="uploadFileExcel">
                    <el-icon class="el-icon--upload">
                        <upload-filled />
                    </el-icon>
                    <div class="el-upload__text">
                        拖放文件 <em>上传文件</em>
                    </div>
                </el-upload>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {
        ref,
        reactive,
        computed,
        watch
    } from 'vue';
    import {
        UploadFilled,
        InfoFilled
    } from '@element-plus/icons-vue'
    import request from '@/utils/request';
    import {
        ElMessage
    } from 'element-plus'
    export default {
        name: '',
        data() {
            return {
                tableData: [],
                current: 1,
                page: 10,
                firstTotal: '',
                currentPage: 1, // 用户当前页
                total: '', // 总页数
                pageSize: 10, // 每页要展示数据条数
                AccountTableData: [], // 接收后台的总数据
                accountCache: [],
                dialogAddPaper: false,
                dialogAddAccount: false,
                dialogUpPaper: false,
                dialogDealFile: false,
                dialogExcel: false,
                searchName: '',
                searchRoles: '',
                searchStatus: '',
                searchPaperName: '',
                searchPublicationName: '',
                searchYear: null,
                loadAddress: '',
                collection: [],
                cheackOrDeal: false,
                oneself: {
                    id: '',
                    sortNumber: '',
                    participantName: '',
                    participationMode: '',
                    workPlace: '',
                    category: '',
                    usersId: '',
                },
                paper: {
                    id: '',
                    paperName: '',
                    publicationName: '',
                    publicationTime: '',
                    isnn: '',
                    cn: '',
                    issueNumber: '',
                    volumeNumber: '',
                    pageRange: '',
                    paperType: '',
                    journalCategory: '',
                    teachingReformPapers: '',
                    highReference: '',
                    scannedPaper: '',
                    collection: '',
                    inputPeople: '',
                    status: '',
                    communicationAuthor: '',
                    communicationUnit: '',
                    participants: [{
                        // id: '',
                        // sortNumber: '',
                        // participantName: '',
                        // participationMode: '',
                        // workPlace: '',
                        // category: ''
                    }],
                    userId: ''
                },
                rules: {
                    publicationTime: [{
                        type: 'date',
                        required: true,
                        message: '请选择发表时间',
                        trigger: 'change',
                    }, ],
                    paperName: {
                        required: true,
                        message: '请输入论文名称',
                        trigger: 'blur',
                    },
                    publicationName: {
                        required: true,
                        message: '请输入发表刊物名称',
                        trigger: 'blur',
                    },
                    paperType: {
                        required: true,
                        message: '请选择类型',
                        trigger: 'change',
                    },
                }
            }
        },
        methods: {
            checkPaper() {
                this.current = 1;
                this.load()
            },
            load() {
                request({
                    url: '/paper',
                    headers: {
                        isToken: true
                    },
                    method: 'get',
                    timeout: 20000,
                    params: {
                        current: this.current,
                        page: this.page,
                        searchPaperName: this.searchPaperName,
                        searchPublicationName: this.searchPublicationName,
                        searchStatus: this.searchStatus,
                        searchYear: this.searchYear==null ? null : this.searchYear.getFullYear()
                    }
                }).then((res) => {
                    this.tableData = res.data.tableData;
                    this.firstTotal = res.data.total;
                    this.loadAddress = res.data.loadAddress;
                });
            },
            checkAdd() {
                this.paper.id = ''
                this.paper.paperName = ''
                this.paper.publicationName = ''
                this.paper.publicationTime = ''
                this.paper.isnn = ''
                this.paper.cn = ''
                this.paper.issueNumber = ''
                this.paper.volumeNumber = ''
                this.paper.pageRange = ''
                this.paper.paperType = ''
                this.paper.journalCategory = ''
                this.paper.teachingReformPapers = false
                this.paper.highReference = false
                this.paper.scannedPaper = ''
                this.paper.collection = ''
                this.paper.inputPeople = ''
                this.paper.status = ''
                this.paper.participants = []
                this.paper.userId = ''
                this.paper.communicationAuthor= ''
                this.paper.communicationUnit= ''
                this.collection = []
                this.oneself = ''
                request({
                    url: '/accounts/getSimpleAccount',
                    headers: {
                        isToken: true
                    },
                    timeout: 20000,
                    method: 'get',
                    params: {}
                }).then((res) => {
                    res.data.user.sortNumber = 1;
                    this.paper.participants.push(res.data.user);
                    this.paper.inputPeople = res.data.user.participantName
                    this.oneself = res.data.user;
                })
                this.dialogAddPaper = true;
            },
            checkUp(row) {
                this.paper.id = row.id
                this.paper.paperName = row.paperName
                this.paper.publicationName = row.publicationName
                this.paper.publicationTime = row.publicationTime
                this.paper.isnn = row.isnn
                this.paper.cn = row.cn
                this.paper.issueNumber = row.issueNumber
                this.paper.volumeNumber = row.volumeNumber
                this.paper.pageRange = row.pageRange
                this.paper.paperType = row.paperType
                this.paper.journalCategory = row.journalCategory
                this.paper.teachingReformPapers = row.teachingReformPapers
                this.paper.highReference = row.highReference
                this.paper.scannedPaper = row.scannedPaper
                this.paper.collection = row.collection
                this.paper.inputPeople = row.inputPeople
                this.paper.status = row.status
                this.paper.participants = row.participants
                this.paper.communicationAuthor= row.communicationAuthor
                this.paper.communicationUnit= row.communicationUnit
                this.paper.userId = row.userId
                if (row.collection != null) this.collection = row.collection.split("&")
                else this.collection = []
                if (row.status == '未提交' || row.status == '审核失效') this.cheackOrDeal = true;
                else this.cheackOrDeal = false;
                this.dialogUpPaper = true
            },
            dealFile(row) {
                this.paper.scannedPaper = row.scannedPaper
                this.paper.id = row.id;
                this.dialogDealFile = true;
                if (row.status == '未提交' || row.status == '审核失效') this.cheackOrDeal = true;
                else this.cheackOrDeal = false;
            },
            deleteFile(row) {
                this.paper.id = row.id
                this.paper.paperName = row.paperName
                this.paper.publicationName = row.publicationName
                this.paper.publicationTime = row.publicationTime
                this.paper.isnn = row.isnn
                this.paper.cn = row.cn
                this.paper.issueNumber = row.issueNumber
                this.paper.volumeNumber = row.volumeNumber
                this.paper.pageRange = row.pageRange
                this.paper.paperType = row.paperType
                this.paper.journalCategory = row.journalCategory
                this.paper.teachingReformPapers = row.teachingReformPapers
                this.paper.highReference = row.highReference
                this.paper.scannedPaper = row.scannedPaper
                this.paper.collection = row.collection
                this.paper.inputPeople = row.inputPeople
                this.paper.status = row.status
                this.paper.communicationAuthor= row.communicationAuthor
                this.paper.communicationUnit= row.communicationUnit
                this.paper.participants = row.participants
                this.paper.userId = row.userId
                request({
                    url: '/paper',
                    headers: {
                        isToken: false
                    },
                    method: 'delete',
                    timeout: 20000,
                    data: this.paper,
                }).then(() => {
                    this.load()
                    ElMessage({
                        showClose: true,
                        message: '删除成功',
                        center: true,
                        type: 'success'
                    })
                })
            },
            addAccount() {
                this.currentPage = 1;
                this.pageSize = 10;
                this.total = '';
                this.accountLoad();
                this.dialogAddAccount = true;
            },
            accountLoad() {
                request({
                    url: '/accounts/getAllSimpleAccount',
                    headers: {
                        isToken: false
                    },
                    timeout: 20000,
                    method: 'get',
                    params: {
                        currentPage: this.currentPage,
                        pageSize: this.pageSize,
                        searchName: this.searchName,
                        searchRoles: this.searchRoles
                    }
                }).then((res) => {
                    this.total = res.data.total;
                    this.AccountTableData = res.data.account;
                })
            },
            handleCurrentChange(currentPage) {
                this.currentPage = currentPage;
                this.accountLoad();
            },
            checkRoles() {
                this.currentPage = 1;
                this.accountLoad();
            },
            handleSelectionChange(selection) {
                this.accountCache = selection
                // console.log(this.accountCache)
            },
            textRowClick(row) {
                this.$refs.multipleTableRef.toggleRowSelection(row);
            },
            addListparticipants() {
                for (let i = 0; i < this.accountCache.length; i++) {
                    if (this.checkRepeatName(this.accountCache[i])) {
                        this.accountCache[i].sortNumber = this.paper.participants.length + 1;
                        this.paper.participants.push(this.accountCache[i]);
                    }
                }
                this.dialogAddAccount = false;
            },
            //vue2语法的this就能用 我这个版本的vue3有可能有问题。。。
            uploadFile(params) {
                const formData = new FormData();
                formData.append("file", params.file);
                const config = {
                    headers: {
                        "Content-Type": "multipart/form-data",
                        isToken: false
                    }
                };
                request.post('/paper/fileCache', formData, config).then((res) => {
                    this.paper.scannedPaper = res.data.saveName;
                    ElMessage({
                        showClose: true,
                        message: '上传成功',
                        center: true,
                        type: 'success'
                    })
                });
            },
            checkRepeatName(object) {
                for (let i = 0; i < this.paper.participants.length; i++) {
                    if (this.paper.participants[i].usersId == object.usersId) {
                        ElMessage({
                            showClose: true,
                            message: object.participantName + '已在人员列表中',
                            center: true,
                            type: 'warning'
                        })
                        return false;
                    }
                }
                return true;
            },
            addOneSelf() {
                if (this.checkRepeatName(this.oneself)) {
                    this.oneself.sortNumber = this.paper.participants.length + 1
                    this.paper.participants.push(this.oneself);
                }
            },
            deleteOne(index) {
                //通过下标删除距离一个位置的内容
                this.paper.participants.splice(index, 1);
            },
            addStudent() {
                this.paper.participants.push({
                    id: '',
                    sortNumber: this.paper.participants.length + 1,
                    participantName: '',
                    participationMode: '',
                    workPlace: '',
                    category: ''
                });
            },
            submitAddPaper(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if (this.paper.participants.length == 0) {
                            ElMessage({
                                showClose: true,
                                message: '请添加参与人员，不然无法添加数据',
                                center: true,
                                type: 'error'
                            })
                        } else {
                            var p = '';
                            for (let i = 0; i < this.collection.length; i++) {
                                p += this.collection[i];
                                if (i < this.collection.length - 1) p += '&';
                            }
                            this.paper.collection = p;
                            request({
                                url: '/paper',
                                headers: {
                                    isToken: true
                                },
                                method: 'post',
                                timeout: 20000,
                                data: this.paper
                            }).then(() => {
                                this.load();
                                this.dialogAddPaper = false
                                this.$refs['upload'].clearFiles('ready')
                                ElMessage({
                                    showClose: true,
                                    message: '添加成功',
                                    center: true,
                                    type: 'success'
                                })
                            });
                        }
                    } else {
                        console.log('error submit!!')
                        return false
                    }
                })
            },
            submitUpPaper(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if (this.paper.participants.length == 0) {
                            ElMessage({
                                showClose: true,
                                message: '请添加参与人员，不然无法添加数据',
                                center: true,
                                type: 'error'
                            })
                        } else {
                            var p = '';
                            for (let i = 0; i < this.collection.length; i++) {
                                p += this.collection[i];
                                if (i < this.collection.length - 1) p += '&';
                            }
                            this.paper.collection = p;
                            request({
                                url: '/paper',
                                headers: {
                                    isToken: false
                                },
                                method: 'put',
                                timeout: 20000,
                                data: this.paper
                            }).then(() => {
                                this.dialogUpPaper = false;
                                this.load();
                                ElMessage({
                                    showClose: true,
                                    message: '修改成功',
                                    center: true,
                                    type: 'success'
                                })
                            });
                        }
                    } else {
                        console.log('error submit!!')
                        return false
                    }
                });
            },
            getFile() {
                request({
                    url: this.loadAddress + "/" + this.paper.scannedPaper + "?time=" + new Date().getTime(),
                    headers: {
                        isToken: false
                    },
                    method: 'get',
                    timeout: 20000,
                    responseType: 'blob',
                }).then((res) => {
                    ElMessage({
                        showClose: true,
                        message: '请稍等正在下载附件',
                        center: true,
                        type: 'success'
                    })
                    let blob = new Blob([res.data])
                    let fileName = this.paper.scannedPaper
                    if (window.navigator.msSaveOrOpenBlob) {
                        navigator.msSaveBlob(blob, fileName)
                    } else {
                        // console.log(3)
                        var link = document.createElement('a')
                        link.href = window.URL.createObjectURL(blob)
                        link.download = fileName
                        link.click()
                        //释放内存
                        window.URL.revokeObjectURL(link.href)
                    }
                }).catch(() => {
                    ElMessage({
                        showClose: true,
                        message: '没有附件',
                        center: true,
                        type: 'error'
                    })
                });
            },
            UpFile(params) {
                const formData = new FormData();
                formData.append("file", params.file);
                if(this.paper.scannedPaper!=null) formData.append("fileName", this.paper.scannedPaper);
                formData.append("id", this.paper.id);
                const config = {
                    headers: {
                        "Content-Type": "multipart/form-data",
                        isToken: false
                    }
                };
                request.post('/paper/upFile', formData, config).then((res) => {
                    this.$refs['updataFile'].clearFiles('ready');
                    this.load();
                    ElMessage({
                        showClose: true,
                        message: '上传成功',
                        center: true,
                        type: 'success'
                    })
                    this.dialogDealFile = false;
                });
            },
            dealStatus(row, name) {
                request({
                    url: '/paper/status',
                    headers: {
                        isToken: false
                    },
                    method: 'put',
                    timeout: 20000,
                    data: {
                        id: row.id,
                        status: name
                    }
                }).then(() => {
                    ElMessage({
                        showClose: true,
                        message: '提交成功，状态为' + name,
                        center: true,
                        type: 'success'
                    })
                    this.load();
                });
            },
            getExcelType() {
                request({
                    url: '/static/excel/paper.xlsx?time=' + new Date().getTime(),
                    headers: {
                        isToken: false
                    },
                    method: 'get',
                    timeout: 20000,
                    responseType: 'blob',
                }).then((res) => {
                    let blob = new Blob([res.data], {
                        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
                    })
                    let fileName = "导入学术论文信息" + '.xlsx'
                    if (window.navigator.msSaveOrOpenBlob) {
                        navigator.msSaveBlob(blob, fileName)
                    } else {
                        // console.log(3)
                        var link = document.createElement('a')
                        link.href = window.URL.createObjectURL(blob)
                        link.download = fileName
                        link.click()
                        //释放内存
                        window.URL.revokeObjectURL(link.href)
                    }
                });
            },
            uploadFileExcel(params) {
                const formData = new FormData();
                formData.append("file", params.file);
                const config = {
                    headers: {
                        "Content-Type": "multipart/form-data",
                        isToken: true
                    }
                };
                request.post('/paper/addExcel', formData, config).then(() => {
                    this.$refs['uploadExcel'].clearFiles('ready');
                    this.load();
                    ElMessage({
                        showClose: true,
                        message: '添加成功，如果学术论文信息存在则不能填加，出现冲突请联系管理员',
                        center: true,
                        type: 'success'
                    })
                    this.dialogExcel = false;
                }).catch(() => {
                    this.$refs['uploadExcel'].clearFiles('ready');
                });

            },
        },
        created() {
            this.load()
        },
        watch: {
            dialogAddPaper(val) {
                if (!val) {
                    this.$refs['upload'].clearFiles('ready')
                }
            }
        },
        setup() {
            return {
                UploadFilled,
                InfoFilled
            }
        }
    }
</script>

<style scoped>

</style>
